# 9.4 导入类
import sys
sys.path.append("D:\Python练习")

from car import Car

class Battery():
    """一次模拟电动汽车电瓶的简化尝试"""

    def __init__(self,battery_size=70):
        """初始化电瓶的属性"""
        self.battery_size=battery_size

    def describe_battery(self):
        """打印一条描述电瓶容量的消息"""
        print("This car has a "+str(self.battery_size)+"-kwh battery.")

    def get_range(self):
        """打印一条消息，指出电瓶的续航里程"""
        if self.battery_size==70:
            range=240
        elif self.battery_size==85:
            range=270



        message="This car can go approximately "+str(range)
        message+=" miles on a full charge."
        print(message)

class ElectricCar(Car):
    """电动汽车的独特之处"""

    def __init__(self,make,model,year):
        """初始化父类的属性"""
        super().__init__(make,model,year)


        self.battery=Battery()

my_tesla=ElectricCar('tesla','model s',2016)

print(my_tesla.get_descriptive_name())
my_tesla.battery.describe_battery()
my_tesla.battery.get_range()


# 9.4.3 从一个模块导入多个类

import sys
sys.path.append("D:\Python练习")
from car_electriccar import Car,ElectricCar


my_tesla=ElectricCar('tesla','model s',2016)

print(my_tesla.get_descriptive_name())
my_tesla.battery.describe_battery()
my_tesla.battery.get_range()




# 9.4.4 或者直接导入模块，用.去引用具体类，推荐使用这种方法

import sys
sys.path.append("D:\Python练习")
import car_electriccar


my_tesla=car_electriccar.ElectricCar('tesla','model s',2016)

print(my_tesla.get_descriptive_name())
my_tesla.battery.describe_battery()
my_tesla.battery.get_range()

# 9.4.5 导入所有类，不推荐，能看懂就行了,类名称容易冲突

import sys
sys.path.append("D:\Python练习")
from car_electriccar import *

my_tesla=ElectricCar('tesla','model s',2016)

print(my_tesla.get_descriptive_name())
my_tesla.battery.describe_battery()
my_tesla.battery.get_range()


# 9.4.6 一个模块引入

import sys
sys.path.append("D:\Python练习")

from car import Car
from electriccar import ElectricCar

my_used_car=Car('subaru','outback',2013)
print(my_used_car.get_descriptive_name())

my_tesla=ElectricCar('tesla','model s',2016)
print(my_tesla.get_descriptive_name())
my_tesla.battery.describe_battery()
my_tesla.battery.get_range()

# 9.5 Python标准库，从模块collection中导类

from collections import OrderedDict

favorite_languages=OrderedDict()
##创建一个空的有序字典

favorite_languages['jen']='python'
favorite_languages['sarah']='c'
favorite_languages['edward']='ruby'
favorite_languages['phil']='python'

for name, language in favorite_languages.items():
    print(name.title()+"'s favorite language is "+language.title()+'.')

# 9.6 字典编码风格 大写不能有下划线 文档字符串

# class Dog

# def_1

# def_2

# Class_1


# Class_2

## import 导入，先导入标准库

## import 自定义模块中的类